@isTest
private class BloodApplicationControllerTest {
    static testMethod void testMethod1() {
         //客户1
        Account acc = TestUtils.createAccount();
        acc.Level__c = '三级甲等';
        insert acc;     

        //业务机会1
        Opportunity opp = TestUtils.createOpportunity();
        opp.AccountId = acc.Id;
        insert opp;

        Id pRT = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');

        	Product__c p1 = TestUtils.createProduct();
	        p1.Name = 'Test1';
	        p1.NCCode__c = '100100100001'; 
	        p1.RecordTypeId = pRT;
	        p1.zl__c = '10';

	        insert p1;

	        Product__c p2 = TestUtils.createProduct();
	        p2.Name = 'Test12';
	        p2.NCCode__c = '100100100002'; 
	        p2.RecordTypeId = pRT;
	        p2.zl__c = '10';

	        insert p2;

	         Product__c p3 = TestUtils.createProduct();
	        p3.Name = 'Test13';
	        p3.NCCode__c = '110220600001'; 
	        p3.RecordTypeId = pRT;
	        p3.zl__c = '10';

	        insert p3;

	         Product__c p4 = TestUtils.createProduct();
	        p4.Name = 'Test14';
	        p4.NCCode__c = '110220600002'; 
	        p4.RecordTypeId = pRT;
	        p4.zl__c = '10';

	        insert p4;

	     IntentProduct__c ip = new IntentProduct__c();
        ip.Product__c = p1.Id;
        ip.Quantity__c = 1;
        ip.SalesPrice__c = 1;
        ip.Opportunity__c = opp.Id;
        insert ip;


        PageReference page1 = new PageReference('/apex/BloodApplication?id=' + opp.Id );
        System.Test.setCurrentPage(page1);

        BloodApplicationController bac = new BloodApplicationController();
        bac.init();

         bac.getDetailFromProduct();

        List<BloodApplicationController.BloodBean> tmp = new List<BloodApplicationController.BloodBean>();
        tmp.add(new BloodApplicationController.BloodBean(ip,p3));

        Map<String,Object> dataM = new Map<String,Object>();
        dataM.put('datas', tmp);
        Map<String,String> baseMap = new Map<String,String>();
        baseMap.put('Account__c', acc.Id);
        baseMap.put('Opportunities__c', opp.Id);
        dataM.put('base', baseMap);

        bac.saveJson = EncodingUtil.urlEncode(JSON.serialize(dataM), 'UTF-8');
        bac.save();

        BloodSugarOrder__c bo = [select Id ,Status__c from BloodSugarOrder__c limit 1 ];
        PageReference page = new PageReference('/apex/BloodApplication?id=' + bo.Id  );
        System.Test.setCurrentPage(page);

        BloodApplicationController bac1 = new BloodApplicationController();
        bac1.init();





        BloodSugarOrder__c b1 = new BloodSugarOrder__c();
        b1.Effect__c  = true;
        b1.Account__c = acc.Id;
        b1.Opportunities__c = opp.Id;
        insert b1;


        bo.Status__c = '审批成功';
        update bo;

        try {
            BloodSugarOrderHander.contractBack(bo);
        }
        catch (Exception e) {
            
        }
        
        






    }
}